package com.midea.oms.Dto;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @projectName: 接口梳理
 * @package: com.midea.oms.Dto
 * @className: PageResponse
 * @author: zhangcan30
 * @description: TODO
 * @date: 2024/3/31 13:36
 * @version: 1.0
 */
public class PageResponse<T> implements Serializable {

    private static final long serialVersionUID = -2103014265407834780L;
    public List<T> list = new ArrayList<>();
    public Integer totalCount = 0;
    public Integer totalPage = 0;
    public Integer pageNo = 1;
    public Integer pageSize = 30;
    public Integer offset = 0;

    public PageResponse() {
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
    }

    public Integer getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    public Integer getPageNo() {
        return pageNo;
    }

    public void setPageNo(Integer pageNo) {
        this.pageNo = pageNo;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getOffset() {
        return offset;
    }

    public void setOffset(Integer offset) {
        this.offset = offset;
    }

    public PageResponse(Integer pageNo, Integer pageSize, Integer totalCount, List<T> list) {
        this.init(pageNo, pageSize, totalCount, list);
    }


    public PageResponse(Integer pageNo, Integer pageSize, Integer totalCount) {
        this(pageNo, pageSize, totalCount, null);
    }

    public PageResponse(Integer pageNo, Integer pageSize) {
        this(pageNo, pageSize, null);
    }

    public void init(Integer pageNo, Integer pageSize, Integer totalCount, List<T> list) {
        if (pageNo != null) {
            this.pageNo = pageNo;
        }
        if (pageSize != null) {
            this.pageSize = pageSize;
        }
        if (this.pageNo > 0) {
            this.offset = this.pageSize * this.pageNo;
        }
        if (totalCount != null) {
            this.totalCount = totalCount;
            totalPage = this.totalCount % pageSize > 0 ? this.totalCount / pageSize + 1 : this.totalCount / pageSize;
        }
        if (list != null) {
            this.list = list;
        }
    }

}
